#include "t_packinfo.h"
#include "ElaScrollPageArea.h"
#include "ElaText.h"
#include "ElaLineEdit.h"
#include "t_setparams.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGlobalStatic>

Q_GLOBAL_STATIC(T_PackInfo,s_instance)

T_PackInfo::T_PackInfo(QWidget *parent)
    : ElaScrollPage(parent)
{
    initPackInfo();
    initUI();

    connect(T_SetParamsIns,&T_SetParams::flushPackInfo,this,&T_PackInfo::on_flushPackInfo);
}

T_PackInfo::~T_PackInfo()
{

}

T_PackInfo *T_PackInfo::Instance()
{
    return s_instance;
}

void T_PackInfo::clearInfo()
{
    m_cLe->clear();
    m_blockNumLe->clear();
    m_groupNumLe->clear();
    m_standerdVol->clear();

    m_voltageRange->clear();
    m_c_b_way->clear();
    m_sumkWh->clear();
    m_sumWeight->clear();

    m_continueOuterKW->clear();
    m_outer_10_kw->clear();
    m_continueInterKW->clear();
    m_pack_l_w_h->clear();
}

void T_PackInfo::flushPackInfo()
{
    m_standerdVol->setText(g_resultInfo.standerdVol);
    m_voltageRange->setText(g_resultInfo.voltageRange);
    m_c_b_way->setText(g_resultInfo.c_b_way);
    m_sumkWh->setText(g_resultInfo.sumkWh);
    m_sumWeight->setText(g_resultInfo.sumWeight);
    m_continueOuterKW->setText(g_resultInfo.continueOuterKW);
    m_outer_10_kw->setText(g_resultInfo.outer_10_kw);
    m_continueInterKW->setText(g_resultInfo.continueInterKW);
    m_pack_l_w_h->setText(g_resultInfo.pack_l_w_h);
}

void T_PackInfo::initUI()
{
    setFixedSize(850,300);

    QWidget* centralWidget = new QWidget(this);
    centralWidget->setWindowTitle("PACK信息");

    QVBoxLayout* centerLayout = new QVBoxLayout(centralWidget);    
    centerLayout->setContentsMargins(0, 0, 0, 0);
    centerLayout->addWidget(m_packInfoArea);
    centerLayout->addStretch();
    addCentralWidget(centralWidget, true, true, 0);
}

void T_PackInfo::initPackInfo()
{
    ElaText *cText = new ElaText("PACK串数",15,this);
    cText->setWordWrap(false);
    m_cLe = new ElaLineEdit(this);
    m_cLe->setEnabled(false);

    ElaText *blockNumText = new ElaText("PACK电芯",15,this);
    blockNumText->setWordWrap(false);
    m_blockNumLe = new ElaLineEdit(this);
    m_blockNumLe->setEnabled(false);

    ElaText *groupNumWText = new ElaText("PACK模组",15,this);
    groupNumWText->setWordWrap(false);
    m_groupNumLe = new ElaLineEdit(this);
    m_groupNumLe->setEnabled(false);
    groupNumWText->hide();
    m_groupNumLe->hide();

    ElaText *c_b_wayText = new ElaText("串并方案",15,this);
    c_b_wayText->setWordWrap(false);
    m_c_b_way = new ElaLineEdit(this);
    m_c_b_way->setEnabled(false);


    QHBoxLayout *hLayout_1 = new QHBoxLayout();
    hLayout_1->addWidget(cText);
    hLayout_1->addSpacing(10);
    hLayout_1->addWidget(m_cLe);
    hLayout_1->addStretch();
    hLayout_1->addWidget(blockNumText);
    hLayout_1->addSpacing(10);
    hLayout_1->addWidget(m_blockNumLe);
    hLayout_1->addStretch();
    hLayout_1->addWidget(c_b_wayText);
    hLayout_1->addSpacing(10);
    hLayout_1->addWidget(m_c_b_way);
    hLayout_1->addStretch();

    ElaText *standerdVolText = new ElaText("标称电压",15,this);
    standerdVolText->setWordWrap(false);
    m_standerdVol = new ElaLineEdit(this);
    m_standerdVol->setEnabled(false);

    ElaText *voltageRangeText = new ElaText("电压范围",15,this);
    voltageRangeText->setWordWrap(false);
    m_voltageRange = new ElaLineEdit(this);
    m_voltageRange->setEnabled(false);

    ElaText *sumkWhText = new ElaText("总能量",15,this);
    sumkWhText->setWordWrap(false);
    m_sumkWh = new ElaLineEdit(this);
    m_sumkWh->setEnabled(false);

    QHBoxLayout *hLayout_2 = new QHBoxLayout();
    hLayout_2->addWidget(standerdVolText);
    hLayout_2->addSpacing(10);
    hLayout_2->addWidget(m_standerdVol);
    hLayout_2->addStretch();
    hLayout_2->addWidget(voltageRangeText);
    hLayout_2->addSpacing(10);
    hLayout_2->addWidget(m_voltageRange);
    hLayout_2->addStretch();
    hLayout_2->addWidget(sumkWhText);
    hLayout_2->addSpacing(10);
    hLayout_2->addWidget(m_sumkWh);

    ElaText *sumWeightText = new ElaText("电池重量",15,this);
    sumWeightText->setWordWrap(false);
    m_sumWeight = new ElaLineEdit(this);
    m_sumWeight->setEnabled(false);

    ElaText *pack_l_w_hText = new ElaText("电池尺寸",15,this);
    pack_l_w_hText->setWordWrap(false);
    m_pack_l_w_h = new ElaLineEdit(this);
    m_pack_l_w_h->setEnabled(false);
    m_pack_l_w_h->setMinimumWidth(200);

    ElaText *outer_10_kwText = new ElaText("10秒峰值放电功率",15,this);
    outer_10_kwText->setWordWrap(false);
    m_outer_10_kw = new ElaLineEdit(this);
    m_outer_10_kw->setEnabled(false);

    QHBoxLayout *hLayout_3 = new QHBoxLayout();    
    hLayout_3->addWidget(sumWeightText);
    hLayout_3->addSpacing(10);
    hLayout_3->addWidget(m_sumWeight);
    hLayout_3->addStretch();
    hLayout_3->addWidget(pack_l_w_hText);
    hLayout_3->addSpacing(10);
    hLayout_3->addWidget(m_pack_l_w_h);
    hLayout_3->addStretch();
    hLayout_3->addWidget(outer_10_kwText);
    hLayout_3->addSpacing(10);
    hLayout_3->addWidget(m_outer_10_kw);

    ElaText *continueOuterKWText = new ElaText("持续放电功率",15,this);
    continueOuterKWText->setWordWrap(false);
    m_continueOuterKW = new ElaLineEdit(this);
    m_continueOuterKW->setEnabled(false);

    ElaText *continueInterKWText = new ElaText("持续充电功率",15,this);
    continueInterKWText->setWordWrap(false);
    m_continueInterKW = new ElaLineEdit(this);
    m_continueInterKW->setEnabled(false);    

    QHBoxLayout *hLayout_4 = new QHBoxLayout();
    hLayout_4->addWidget(continueOuterKWText);
    hLayout_4->addSpacing(10);
    hLayout_4->addWidget(m_continueOuterKW);
    hLayout_4->addStretch();
    hLayout_4->addWidget(continueInterKWText);
    hLayout_4->addSpacing(10);
    hLayout_4->addWidget(m_continueInterKW);
    hLayout_4->addStretch();

    m_packInfoArea = new ElaScrollPageArea(this);
    m_packInfoArea->setFixedSize(800,250);

    QVBoxLayout* vLayout = new QVBoxLayout(m_packInfoArea);
    vLayout->addLayout(hLayout_1);
    vLayout->addSpacing(10);
    vLayout->addLayout(hLayout_2);
    vLayout->addSpacing(10);
    vLayout->addLayout(hLayout_3);
    vLayout->addSpacing(10);
    vLayout->addLayout(hLayout_4);
    vLayout->addStretch();
}

void T_PackInfo::on_flushPackInfo(int c_num,int sum_num, int group_num)
{
    m_cLe->setText(QString::number(c_num));
    m_blockNumLe->setText(QString::number(sum_num));
    m_groupNumLe->setText(QString::number(group_num));
}
